home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dr.bub / 96000.lha / 96000 / appb / b131.asm < prev    next >
Assembly Source File  |  1992-04-28  |  3KB  |  91 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.31    Unsigned Integer Divide
  8. ;The unsigned integer divide operation divides two 32 bit unsigned  integers.  The following code di-
  9. ;vides d0/d2 with  the resulting quotient in d0 and the remainder in d1.  
  10. ;              Unsigned 32 Bit Integer                       Program    ICycles
  11. ;                Division of d0 = d0/d2                      Words
  12.     eor    d1,d1              ; clear d1
  13.     do     #32,dloop          ;32 quotient bits            2        3 
  14.     rol    d0                 ;dividend bit out, q bit in  1        1 
  15.     rol    d1                 ;put in temp                 1        1 
  16.     cmp    d2,d1              ;check for q bit             1        1 
  17.     sub    d2,d1    ifcc      ;update if less              1        1 
  18. dloop 
  19.     rol    d0                 ;last q bit                  1        1 
  20.     not    d0                 ;complement q bits           1        1 
  21. ;                                                          ---      --- 
  22. ;                                                  Totals:  8       133 
  23.  
  24.  
  25. ;The final  remainder is not produced.  This program  may calculate only the number of quotient bits re-
  26. ;quired and has variable  execution time.  
  27.  
  28. ;              Unsigned 32 Bit Integer                       
  29. ;            Division of d0 = d0/d1, d0>=d1                  
  30.     cmp    d1,d0    d0.l,d2.m
  31.     eor    d0,d0    iflo
  32.     jlo    divdone        ; divisor > dividend
  33.     bfind    d0,d0    d3.l,d8.l
  34.     jmi    dive2big        ;dividend has 
  35.                 ;32 significant bits
  36.     bfind    d1,d2    d0.h,d0.l    ;find # of quotient bits
  37.     movei    #32,d3
  38.     move        d2.h,d2.l
  39.     sub    d0,d2    d2.m,d0.l
  40.     inc    d2    d2.l,d2.h    ;compute loop iteration count
  41.     sub    d2,d3
  42.     lsl    d2,d1    d3.l,d2.h    ;align divisor
  43.     do    d2.l,divloop_fast
  44.     cmp    d1,d0        ;perform test subtract
  45.     sub    d1,d0    ifhs    ;if no borrow, do subtract
  46.     rol    d0        ;mult remx2, save quo. bit (borrow)
  47. divloop_fast
  48.     not    d0    d8.l,d3.l    ;flip inverted quotient
  49.     lsl    d2,d0        ;clean off any remainder
  50.     lsr    d2,d0
  51.     jmp    divdone        ;done
  52. dive2big    eor    d2,d2
  53.     do    #32,divloop_slow        ;same algorithm as 1st routine
  54.     rol    d0
  55.     rol    d2
  56.     cmp    d1,d2
  57.     sub    d1,d2    ifhs
  58. divloop_slow     rol    d0
  59.     not    d0
  60.  
  61. divdone    end
  62.  
  63. ;The final quotient is not produced.  This program may calculate only the number of quotient bits re-
  64. ;quired and has variable  execution time.  
  65. ;              Unsigned 32 Bit Integer                       
  66. ;            Remainder of d0 = d0 rem d1, d0>=d1             
  67.     cmp    d1,d0    d0.l,d2.m
  68.     jlo    divdone        ;divisor > dividend
  69.     bfind    d0,d0    #0,d2.l
  70.     jmi    dive2big        ;dividend has 
  71.                 ;32 significant bits
  72.     bfind    d1,d2    d0.h,d0.l    ;find # of remainder bits
  73.     move        d2.h,d2.l
  74.     sub    d0,d2    d2.m,d0.l
  75.     inc    d2    d2.l,d2.h    ;compute loop count
  76.     lsl    d2,d1    d2.l,d2.h    ;align divisor
  77.     do    d2.l,remloop_fast
  78.     cmp    d1,d0        ;perform test subtract
  79.     sub    d1,d0    ifhs    ;if no borrow, perform subtract
  80.     rol    d0        ;adjust remainder
  81. remloop_fast     lsr    d2,d0        ;align remainder
  82.     jmp    remdone        ;done
  83. dive2big    do    #32,remloop_slow        ;same algorithm as 1st routine
  84.     rol    d0
  85.     rol    d2
  86.     cmp    d1,d2
  87.     sub    d1,d2    ifhs
  88. remloop_slow     tfr    d2,d0
  89. remdone    end
  90.